#include "mytest.h"
#include "ui_mytest.h"

#include "mythread1.h"

MyTest::MyTest(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MyTest)
{
    ui->setupUi(this);

    mythread1* t1 = new mythread1;
    mythread2* t2 = new mythread2;
    mythread3* t3 = new mythread3;

    connect(this, &MyTest::sendNum, t1, &mythread1::recvNum);

    connect(ui->start, &QPushButton::clicked, [=](){
        emit sendNum(1000);
        t1->start();
    });

    connect(t1, &mythread1::sendArray, t3, &mythread3::recvArray);
    connect(t1, &mythread1::sendArray, t2, &mythread2::recvArray);  //信号和槽的连接顺序也很重要的！！！
    connect(t1, &mythread1::sendArray, [=](QVector<int> v){
        t2->start();
        t3->start();

        for(int i = 0; i < v.size(); i++)
        {
            ui->randomList->addItem(QString().number(v[i]));
        }
    });



    connect(t2, &mythread2::sendArray, [=](QVector<int> v){
        for(int i = 0; i < v.size(); i++)
        {
            ui->bubbleList->addItem(QString().number(v[i]));
        }
    });

    connect(t3, &mythread3::sendArray, [=](QVector<int> v){

        for(int i = 0; i < v.size(); i++)
        {
            ui->quickList->addItem(QString().number(v[i]));
        }
    });
}

MyTest::~MyTest()
{
    delete ui;
}

